package com.maotouying.owlsmart.homePage;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.maotouying.owlsmart.R;

import java.util.ArrayList;

import jp.wasabeef.glide.transformations.CropCircleTransformation;


public class younglady_A extends BaseAdapter implements ListAdapter {


        private ArrayList<younglady_C> younglady_cs;
        private int id;
        private Context context;
        private LayoutInflater inflater;

        public younglady_A(int sub_item, Context context, ArrayList<younglady_C> younglady_cs) {
            this.younglady_cs = younglady_cs;
            this.context = context;
            this.id = sub_item;
            inflater = LayoutInflater.from(context);

        }

        @Override
        public int getCount() {
            return younglady_cs.size();
        }

        @Override
        public Object getItem(int i) {
            return younglady_cs.get(i);
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @SuppressLint("WrongConstant")
        @Override

        public View getView(int i, View view, ViewGroup viewGroup) {

            //String mty_id,mty_province,mty_date_add,mty_feature,mty_business,mty_price,mty_photos;

            TextView mty_id = null;
            TextView mty_province = null;
            TextView mty_date_add = null;

            TextView mty_feature = null;
            TextView mty_business = null;
            TextView mty_price = null;
            ImageView mty_photos = null;

            ViewHolder viewHolder;
            if (view == null) {
                view = inflater.inflate(id, null);

                //mty_id,mty_province,mty_date_add,mty_feature,mty_business,mty_price,mty_photos;

                mty_id = (TextView) view.findViewById(R.id.mty_id);
                mty_province = (TextView) view.findViewById(R.id.mty_province);
                mty_date_add = (TextView) view.findViewById(R.id.mty_date_add);

                mty_feature = (TextView) view.findViewById(R.id.mty_feature);
                mty_business = (TextView) view.findViewById(R.id.mty_business);
                mty_price = (TextView) view.findViewById(R.id.mty_price);
                mty_photos = (ImageView) view.findViewById(R.id.mty_photos);
                view.setTag(new ViewHolder(mty_id,mty_province,mty_date_add,mty_feature,mty_business,mty_price,mty_photos));
            } else {
                ViewHolder viewHolder1 = (ViewHolder) view.getTag(); // 重新获取ViewHolder
                mty_id = viewHolder1.mty_id;
                mty_province = viewHolder1.mty_province;
                mty_date_add = viewHolder1.mty_date_add;

                mty_feature = viewHolder1.mty_feature;
                mty_business = viewHolder1.mty_business;
                mty_price = viewHolder1.mty_price;
                mty_photos = viewHolder1.mty_photos;
            }
            younglady_C cc = (younglady_C) younglady_cs.get(i); // 获取当前项的实例

            mty_id.setText(cc.getMty_id().toString());//对象为空
            mty_province.setText(cc.getMty_province().toString());
            mty_date_add.setText(cc.getMty_date_add().toString());

            mty_feature.setText(cc.getMty_feature().toString());
            mty_business.setText(cc.getMty_business().toString());
            mty_price.setText(cc.getMty_price().toString());

            RequestOptions options = RequestOptions.bitmapTransform(new CropCircleTransformation());
            Glide.with(context)
                    .load(cc.getMty_photos().toString())
                    //.placeholder(R.drawable.ic_default_image)
                    .error(R.drawable.ic_girl)
                    .apply(options)
                    .into(mty_photos);


            return view;

        }


        private final class ViewHolder {

            TextView mty_id = null;
            TextView mty_province = null;
            TextView mty_date_add = null;

            TextView mty_feature = null;
            TextView mty_business = null;
            TextView mty_price = null;
            ImageView mty_photos = null;

            public ViewHolder(TextView mty_id, TextView mty_province, TextView mty_date_add,TextView mty_feature, TextView mty_business, TextView mty_price,ImageView mty_photos) {
                this.mty_id = mty_id;
                this.mty_province = mty_province;
                this.mty_date_add = mty_date_add;
                this.mty_feature = mty_feature;

                this.mty_business = mty_business;
                this.mty_price = mty_price;
                this.mty_photos = mty_photos;
            }

        }

}
